package com.zy.mc_module.mvp.model;

import com.zy.mc_module.mvp.bean.BaseBean;
import com.zy.mc_module.mvp.bean.ProtocolBean;
import com.zy.mc_module.mvp.bean.TokenBean;
import com.zy.mc_module.mvp.bean.UserBean;
import com.zy.mc_module.mvp.contract.LoginContract.Model;
import com.zy.mc_module.utils.UserUtils;
import com.zy.mc_module.utils.retrofit.RetrofitManager;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created on 18/11/30
 * 登录
 */
public class LoginModel implements Model {

    @Override
    public Observable<BaseBean<UserBean>> checkLogin(Object... objects) {
        Map<String, Object> map = new HashMap<>();
        map.put("phone", objects[0]);
        map.put("code", objects[1]);
        map.put("openid", objects[2]);
        map.put("uuid", objects[3]);
        map.put("nickname", objects[4]);
        map.put("headimgurl", objects[5]);
        return RetrofitManager.getInstance().getApi().checkLogin(map);
    }

    @Override
    public Observable<TokenBean> login(int type, String userName, String phone, String password) {
        Map<String, Object> map = new HashMap<>();
        map.put("username", userName);
        map.put("password", password);
//        map.put("type", type);
        if (type == 1) {//登录类型 1 账号密码登录 2 短信登录
            map.put("password", (password));
            return RetrofitManager.getInstance().getApi().login(map);
        } else {
            map.put("code", password);
            return RetrofitManager.getInstance().getApi().codeLogin(map);
        }
    }

    public Observable<UserBean> getUserInfo(){
        return RetrofitManager.getInstance().getApi().getUserInfo();
    }
    public Observable<ResponseBody> getImgCode(String phone) {
        return RetrofitManager.getInstance().getApi().getImgCode(phone);
    }
    @Override
    public Observable<BaseBean> checkCode(String phone, String code) {
        Map<String, Object> map = new HashMap<>();
        map.put("source", "1");
        map.put("code", code);
        map.put("mobile", phone);
        return RetrofitManager.getInstance().getApi().checkCode(map);
    }

    public Observable<ResponseBody> register(String phone,String registerCode){
        Map<String, Object> map = new HashMap<>();
        map.put("username", phone);
        map.put("registerCode",registerCode);
        return RetrofitManager.getInstance().getApi().register(map);
    }

    @Override
    public Observable<BaseBean<Boolean>> checkPhoneRegister(String phone) {
        Map<String, Object> map = new HashMap<>();
        map.put("phone", phone);
        return RetrofitManager.getInstance().getApi().checkPhoneRegister(map);
    }

    @Override
    public Observable<BaseBean<ProtocolBean>> queryArticleProtocol(String articleProtocolType, String queryType) {
        Map<String, Object> map = new HashMap<>();
        map.put("articleProtocolType", articleProtocolType);//9,会员中心公告,10,商家公告,11,合作人中心公告,12,开通会员协议,13,注册协议,14,隐私政策,15,邀请有礼活动规则,16,无忧会员卡
        map.put("queryType", queryType);//查询类型，1-只需要标题，2-查询内容
        return RetrofitManager.getInstance().getApi().queryArticleProtocol(map);
    }


    /***
     * 绑定银行卡
     * @param objects
     * @return
     */
    @Override
    public Observable<BaseBean> bindBank(Object... objects) {
        Map<String, Object> map = new HashMap<>();
        return RetrofitManager.getInstance().getApi().bindBank(map);
    }
}
